'''
Created on Jul 28, 2010

@author: behrooz
'''
from django.template.context import RequestContext
from django.shortcuts import render_to_response as rtr
from urlparse import urlparse

def render_to_response(request, *args, **kwargs):
    if kwargs is None:
        kwargs = {}
    kwargs['context_instance'] = RequestContext(request)
    return rtr(*args, **kwargs)

def meta_netloc(request):
    referer = request.META.get('HTTP_REFERER', None)
    if referer is None:
        return None
    url = urlparse(referer)
    if url.netloc is None or url.netloc == '':
        return referer
    return url.netloc

def meta_remote_ip(request):
    return request.META.get('REMOTE_ADDR', None)